package itemCalc.common;

import java.io.File;
import java.util.logging.Logger;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.Property;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;



@Mod(modid=Reference.MODID, name=Reference.NAME, version=Reference.VERSION)
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class mod_itemCalc {
	public Logger log;
	public int ID = 601;
	public static Block itemCalculator;
	public GuiHandler guiHandler;
	
	@Instance(Reference.MODID)
	public static mod_itemCalc instance;
	
	@SidedProxy(clientSide="itemCalc.client.ClientProxy", serverSide="itemCalc.common.CommonProxy")
	public static CommonProxy proxy;

	@EventHandler
	public void preInit(FMLPreInitializationEvent event) {
		
		log = event.getModLog();
		File configDir = event.getSuggestedConfigurationFile();
		Configuration config;
		try{
			config = new Configuration(configDir);
			config.load();
			log.info(new StringBuilder().append("Config loaded from ").append(configDir.getAbsolutePath()).toString());
		} catch (Exception e) {
			log.warning(new StringBuilder().append("Error while trying to access configuration! ").append(e).toString());
			config = null;
		}
		
		

		if(config != null){
			Property prop = config.get("block", "Calculator ID", ID);
			ID = prop.getInt(600);

			if(config.hasChanged()) config.save();
		}

	}

	@EventHandler
	public void load(FMLInitializationEvent event) {

		itemCalculator = new BlockItemCalc(this.ID).setHardness(2.5F).setStepSound(Block.soundWoodFootstep);
		GameRegistry.registerBlock(itemCalculator, "itemCalculator");
		LanguageRegistry.addName(itemCalculator, "itemCalculator");
		//GameRegistry.addRecipe(new ItemStack(itemCalculator, 1), "BDB", "ACA", "AAA", 'A', Block.planks, 'B', Item.ingotIron, 'C', Block.workbench, 'D', Item.diamond);
		
		NetworkRegistry.instance().registerGuiHandler(this, guiHandler);

	}

	@EventHandler
	public void postInit(FMLPostInitializationEvent event) {
		
	}
}




